package com.yxw.yxnet_cd_center.customer_service.controller;

import com.yxw.yxnet_cd_center.customer_service.dto.*;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.customer_service.service.FlockService;
import com.yxw.yxnet_cd_center.customer_service.service.WorkflowService;
import com.yxw.yxnet_cd_center.customer_service.vo.FlowRuleVo;
import com.yxw.yxnet_cd_center.customer_service.vo.YxCsFlockVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 工作群管理
 * @author liuxin
 * @date 2023.09.14
 */
@RestController
@Api(value = "工作群管理", tags = "工作群管理")
@Slf4j
@RequestMapping("/flock")
public class FlockController {

    @Autowired
    private FlockService flockService;

    @ApiOperation(value = "工作组分群-设置群")
    @PostMapping(value = "/addFlock")
    public BaseResult addFlock(@RequestBody @Validated FlockAddDTO dto) {
        flockService.addFlock(dto);
        return BaseResult.doSuccess(null, "设置成功");
    }

    @ApiOperation(value = "工作组分群-设置群详情页查询群列表")
    @GetMapping(value = "/getFlockListByAddFlock")
    public BaseResult getFlockListByAddFlock(@RequestParam Long groupId) {
        List<FlockDTO> flockList= flockService.getFlockListByAddFlock(groupId);
        return BaseResult.doSuccess(flockList, "查询成功");
    }

    @ApiOperation(value = "分流管理-群列表查询")
    @PostMapping(value = "/getFlockList")
    public BaseResult<PageVO<YxCsFlockVo>> getFlockList(@RequestBody FlockQueryDTO dto) {
        PageVO<YxCsFlockVo> pageVo = flockService.getFlockList(dto);
        return ResultHelper.fillWithSuccess(pageVo);
    }

    @ApiOperation(value = "分流管理-群启用/禁用")
    @PostMapping(value = "/updateFlockStatusById")
    public BaseResult updateFlockStatusById(@RequestBody @Valid  StatusUpdateDTO dto) {
        flockService.updateFlockStatusById(dto);
        return BaseResult.doSuccess(null, "设置成功");
    }

    @ApiOperation(value = "分流管理-设置分流规则")
    @PostMapping(value = "/addWorkflowRule")
    public BaseResult addWorkflowRule(@Validated @RequestBody FlowRuleAddDTO dto) {
        flockService.addWorkflowRule(dto);
        return BaseResult.doSuccess(null,"设置成功");
    }

    @ApiOperation(value = "分流管理-设置分流规则查询")
    @PostMapping(value = "/getWorkflowRuleList")
    public BaseResult<List<FlowRuleVo>> getWorkflowRuleList(@Valid @RequestBody FlowRuleQueryDTO dto) {
        List<FlowRuleVo> flowRuleList=flockService.getWorkflowRuleList(dto);
        return BaseResult.doSuccess(flowRuleList,"查询成功");
    }

    @ApiOperation(value = "工作群成员删除/新增")
    @PostMapping(value = "/saveFlockUser")
    public BaseResult saveFlockUser(@Valid @RequestBody FlockUserUpdateDTO dto) {
        flockService.saveFlockUser(dto);
        return BaseResult.doSuccess(null,"操作成功");
    }

    @ApiOperation(value = "工作群群主转移")
    @PostMapping(value = "/updateFlockLeader")
    public BaseResult updateFlockLeader(@Valid  @RequestBody FlockLeaderUpdateDTO dto) {
        flockService.updateFlockLeader(dto);
        return BaseResult.doSuccess(null,"群主移交成功");
    }

    @ApiOperation(value = "工作群详情查询")
    @GetMapping(value = "/getFlockById")
    public BaseResult getFlockById(@RequestParam Long flockId) {
        YxCsFlockVo voList=flockService.getFlockById(flockId);
        return BaseResult.doSuccess(voList,"查询成功");
    }
}